#include "databaseconnector.h"

DatabaseConnector::DatabaseConnector(QObject *parent) :
    QObject(parent)
{
}


void DatabaseConnector::setDb_user (QString input)
{
    db_user = input;
}

void DatabaseConnector::setDb_pass (QString input)
{
    db_pass = input;
}

void DatabaseConnector::setDb_host (QString input)
{
    db_host = input;
}

void DatabaseConnector::setDb_port (int input)
{
    db_port = input;
}

void DatabaseConnector::setDb_type (QString input)
{
    db_type = input;
}

QString DatabaseConnector::getDb_user (void)
{
    return db_user;
}

QString DatabaseConnector::getDb_pass (void)
{
    return db_pass;
}

QString DatabaseConnector::getDb_host (void)
{
    return db_host;
}

int DatabaseConnector::getDb_port (void)
{
    return db_port;
}

QString DatabaseConnector::getDb_type (void)
{
    return db_type;
}

bool DatabaseConnector::connectNow( void )
{
    db = QSqlDatabase::addDatabase(getDb_type());

    if (getDb_type() == "QSQLITE"){
        db.setDatabaseName(getDb_host());
    }

    if (getDb_type() != "QSQLITE"){
        db.setUserName(getDb_user());
        db.setPassword(getDb_pass());
        db.setPort(getDb_port());
    }

    return db.open();

}

QSqlError DatabaseConnector::lastError( void )
    {
    // If opening database has failed user can ask
    // error description by QSqlError::text()
    return db.lastError();
    }

bool DatabaseConnector::disconnectNow( void )
{

}
